package com.octopus.yangj.customized.rule;

import com.octopus.kernal.controller.SearchOperator;
import com.octopus.kernal.model.BaseStruct;
import com.octopus.kernal.service.BusinessRuleInterface;
import com.octopus.yangj.customized.service.CustomizedEventService;
import com.octopus.yangj.generated.controller.SearchEventCommand;
import com.octopus.yangj.generated.model.ClientStruct;
import com.octopus.yangj.generated.model.EventStruct;
import com.octopus.yangj.util.ServiceFactory;

public class ClientDeleteRule implements BusinessRuleInterface{

	@Override
	public boolean isAllowed(BaseStruct struct) {
		ClientStruct client = (ClientStruct)struct;
		SearchEventCommand searchCommand = new SearchEventCommand();
		searchCommand.setEntity(new EventStruct());
		searchCommand.setOperator(new EventStruct());
		searchCommand.getEntity().setClientId(client.getId());
		searchCommand.getOperator().setClientId(Long.valueOf(SearchOperator.EQUAL.ordinal()));
		CustomizedEventService eventService = ServiceFactory.getEventService();
		int count = eventService.searchCount(searchCommand);
		if(count > 0){
			return false;
		}else{
			return true;
		}
	}

}
